package com.hzit.controller;

import com.hzit.entity.User;
import com.hzit.service.IUserService;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author lmy
 * @since 2025-01-13
 */
@RestController
@RefreshScope
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @Value("${student.sname}")
    private String sname;
    @Value("${student.age}")
    private int age;
    @Resource
    private LoadBalancerClient client;
    @Value("${classes.cname}")
    private String cname;
    @Value("${server.port}")
    public int port;
    //查询商品列表
    @GetMapping("/list")
    public R<List<User>> list(){
        URI uri = client.choose("hzit-manager").getUri();
        return R.ok(userService.list());
    }

    @GetMapping("/getConfig")
    public R<Map> getConfig(){
        Map<String,Object> map = new HashMap<>();
        map.put("sname",sname);
        map.put("age",age);
        map.put("cname",cname);
        return R.ok(map);
    }

    @GetMapping("getPort")
    public R getPort(){
        Map<String,Object> map = new HashMap<>();
        map.put("port",port);
        return R.ok(map);
    }
}
